package Task1;

public class Student {
    public Student(){}

    private int id;
    private int age;
    private String name;


    public Student(String name, int id, int age) throws AgeException, IdException {
        setName(name);
        setAge(age);
        setId(id);
    }

    public void setName(String name){
        this.name = name;
    }
    public String getName(){
        return name;
    }

    public int getAge() {
        return age;
    }

    // 抛出年龄异常
    public void setAge(int age) throws AgeException {
        if(age < 0 || age > 100){
            throw new AgeException("年龄不合理！");
        }else{
            this.age = age;
        }
    }

    public int getId() {
        return id;
    }

    //抛出学号异常
    public void setId(int id) throws IdException {
        if(id < 0){
            throw new IdException("学号不符合要求！");
        }else{
            this.id = id;
        }
    }

    @Override
    public String toString(){
        return "Task1.Student{" + "name = " + name + "id = " + id + "age= " + age + '}';
    }

    @Override
    public boolean equals(Object object){
        if(object instanceof Student){
            Student stu = (Student) object;
            return (this.getName().equals(stu.getName()) && (this.getId() == ((Student) object).getId()));

        }
        return false;

    }


}
